package jpb.module.service.member;

import jpb.module.dao.keyvalue.KeyValueDao;
import jpb.module.dao.member.MemberDao;
import jpb.module.dao.member.MemberLogDao;
import jpb.module.dao.organize.OrganizeMemDao;
import jpb.module.daomain.member.Member;
import jpb.module.daomain.member.OrgMem;
import jpb.util.DateFormatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by haol on 2017/4/8.
 */
@Service
public class MemberService {
        @Autowired
        private MemberDao memberDao;
        @Autowired
        private OrganizeMemDao organizeMemDao;
        @Autowired
        private MemberLogDao memberLogDao;

        @Autowired
        private KeyValueDao keyValueDao;
        public boolean getUsingValue(int key) {
                return keyValueDao.getValue(key) == 0;
        }

        public void register(String memberNum) {
                Member member = new Member();
                member.setMemberNum(memberNum);
                member.setCreateTime(DateFormatUtil.getYMdHm());
                memberLogDao.register(member);
        }



        public void updatePro(String memberNum, String oid, Integer pid) {
                OrgMem orgMem = new OrgMem();
                orgMem.setNum(memberNum);
                orgMem.setOid(oid);
                orgMem.setPid(pid);
                organizeMemDao.updatePid(orgMem);
        }

        public Member get(String memberNum) {
                return memberDao.get(memberNum);
        }
        public Member getMsg(String memberNum) {

                return memberDao.getMsg(memberNum);
        }
        public Member getLog(String memberNum) {
                return memberLogDao.get(memberNum);
        }



        public void complete(Member member) {
                //姓名。一个电话，
                memberDao.complete(member);
                memberDao.updateTime(member.getMemberNum(), DateFormatUtil.getYMdHm());
        }

        public void update(Member member) {
                memberDao.update(member);
                memberDao.updateTime(member.getMemberNum(), DateFormatUtil.getYMdHm());

        }


        public void updateLoginTime(String num, Date date) {
                memberLogDao.updateLoginTime(num, date);
        }

        public int getCount(String memberNum) {
                return memberDao.getCount(memberNum);
        }


}
